package com.sjz.vhr.controller.system;

import com.sjz.vhr.model.Hr;
import com.sjz.vhr.model.RespBean;
import com.sjz.vhr.model.Role;
import com.sjz.vhr.service.HrService;
import com.sjz.vhr.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/system/hr")
public class HrController {


    @Autowired
    HrService hrService;
    @Autowired
    RoleService roleService;

    // 查询所有用户
    @GetMapping("/")
    public List<Hr> getAllHrs(String keywords) {
        return hrService.getAllHrs(keywords);
    }

    // 更新用户状态
    @PutMapping("/")
    public RespBean updateHr(@RequestBody Hr hr){  //这是一个json对象，要加@RequestBody
        if (hrService.updateHr(hr) == 1){
            return  RespBean.ok("更新成功！");
        }
        return RespBean.error("更新失败！");
    }

    // 查询所有角色
    @GetMapping("/roles")
    public List<Role> getAllRoles(){
        return roleService.getAllRoles();
    }

    // 更新角色
    @PutMapping("/roles")
    public RespBean updateHrRole(Integer hrid, Integer[] rids){
        if (hrService.updateHrRole(hrid,rids)){
            return RespBean.ok("更新角色成功！");
        }
        return RespBean.error("更新角色失败！");
    }

    // 删除用户
    @DeleteMapping("/{id}")
    public RespBean deleteHrById(@PathVariable Integer id){
        if (hrService.deleteHrById(id)==1){
            return RespBean.ok("删除成功");
        }
        return RespBean.error("删除失败");
    }


}